/*
* Copyright 2018 Shanxi Lu'an Taihang Laihui Net Tech co.,LTD.
*/
package com.laihuichuxing.pool.impl;

import com.laihuichuxing.common.config.CacheConfig;
import com.laihuichuxing.mongo.client.GeoSpatialMongoClient;
import com.laihuichuxing.mongo.model.ConnModel;
import com.laihuichuxing.mq.constant.MongoConst;
import com.laihuichuxing.pool.DriverLbs4MongoPool;
import com.laihuichuxing.pool.dto.DriverLbsDto;
import com.laihuichuxing.pool.dto.UserLbsDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Description:
 *
 * @author: Qinxuefeng
 * @since: 1.0
 * Create Date Time: 2018/11/2 11:48
 * Update Date Time:
 */
@Service
public class DriverLbs4MongoPoolImpl extends BaseLbs4Mongo implements DriverLbs4MongoPool {
    @Autowired
    private MongoConst mongoConst;
    private Logger logger = LoggerFactory.getLogger(DriverLbs4MongoPoolImpl.class);

    @Override
    public DriverLbsDto take(UserLbsDto userLbsDto) {
        List<Map<String, String>> lbsDtos = take(userLbsDto,1);
        if(lbsDtos.size()>0){
            DriverLbsDto driverLbsDto1 = new DriverLbsDto();
            driverLbsDto1.setPhone(lbsDtos.get(0).get("mobile"));
            driverLbsDto1.setCityZone(userLbsDto.getCityZone());
            return driverLbsDto1;
        }
        return null;
    }

    @Override
    public List<Map<String, String>> take(UserLbsDto userLbsDto, int ListSize) {
        try {
            List<Map<String, String>> list = take(userLbsDto.getCityZone(), userLbsDto.getLongitude(),
                    userLbsDto.getLatitude(),userLbsDto.getPhone(),ListSize,
                    mongoConst.getMinDistance(), mongoConst.getMaxDistance());
            return list;
        } catch (Exception e) {
            logger.error("获取司机出错,{}",e.toString(),e);
            return null;
        }
    }



    @Override
    public GeoSpatialMongoClient getClient(String cityCode, String phone) {
        ConnModel connModel = new ConnModel(mongoConst.getHost(), mongoConst.getPort(), mongoConst.getUserName(), mongoConst.getPassword(), mongoConst.getDatabase());
        GeoSpatialMongoClient client = new GeoSpatialMongoClient(connModel);
        client.getCollection(CacheConfig.DRIVERLBS + cityCode);
        return client;
    }
    @Override
    public String takeMe(String mobile,String cityCode){
        try {
            return super.takeMe(mobile,cityCode);
        } catch (Exception e) {
            logger.error("获取自己出错,{}",e.toString(),e);
        }
        return "";
    }
}
